﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 打包->加载流程
/// 1.给预制体和资源设置bundle名
/// 2.编写编辑器脚本，点击菜单，生成bundle
/// 3.编写运行时脚本，加载bundle
/// 4.先加载bundle，在加载bundle中的预制体或者图片等资源
/// </summary>
public class LoadAB : MonoBehaviour
{
    IEnumerator Start()
    {
        //本地地址IP
        //string path = "file://" + Application.streamingAssetsPath + "/picture.unity3d";

        //服务器地址IP
        string url = "http://192.168.108.11/StreamingAssets/picture.unity3d";

        WWW www = new WWW(url);

        yield return www;

        AssetBundle ab = www.assetBundle;//占着内存
        GameObject cubePrefab = ab.LoadAsset<GameObject>("Cube");
        var go = Instantiate(cubePrefab);

        Texture tex = ab.LoadAsset<Texture>("GhostDao");
        go.GetComponent<MeshRenderer>().material.mainTexture = tex;

        ab.Unload(false);//只释放assetbundle
        //ab.Unload(true);//只释放bundle和预制体
        var goa = Instantiate(cubePrefab);
    }
}
